package DTaskTaskApp;
use Mojo::Base 'Mojolicious';

use Mojo::IOLoop;


sub startup {
	my $self = shift;
	say "call startup $self";
	my $r = $self->routes;

	my $support_services = [qw(gerrit bugzilla product_requirement design_image)];

	$r->get('/hello')->to('task#hello');


	#imp
	$r->post('/')->to('task#newTask')->name("NewTask");


	my $task_with_id = $r->route('/:task_id/')->to(controller => 'Task');

	#imp
	$task_with_id->get('/')->to(action => 'getTaskInfo')->name('GetTaskInfo');

	$task_with_id->get('/link_info')
		->to(action => 'getTaskLinksInfo')
		->name(action => 'GetTaskLinksInfo');

	#imp
	$task_with_id->delete('/')->to( action => "removeTask")->name('RemoveTask');

#	#not imp debug
#	$task_with_id->get('/debug/treeview')->to(action => "treeView")->name("TaskTreeView");

	#imp
	$task_with_id->put('/tower/todo/:todo_guid')
		->to(action => 'setTaskTowerTodo')
		->name('SetTaskTowerTodo');

	#imp
	$task_with_id->get('/tower/todo/')
		->to(action => 'getTaskTowerTodo')
		->name('GetTaskTowerTodo');

	#imp
	$task_with_id->delete('/tower/todo/')
		->to(action => 'removeTaskTowerTodo')
		->name('RemoveTaskTowerTodo');

	#child
	#not imp
	$task_with_id->put('/child/:sub_task_id')->to(action => 'addChild')->name('TaskAddChild');
	#not imp
	$task_with_id->delete('/child/:sub_task_id')->to(action => 'removeChild')->name('TaskRemoveChild');


	#imp
	$task_with_id->get('/link')->to(action => 'getTaskLinks')->name("GetTaskLinks");

	#imp
	$task_with_id->get('/link/:target', [target => $support_services ])
		->to(action => 'getTaskLinksByTarget')
		->name("GetTaskLinksByTarget");

	#Link target_id with task_id

	#imp
	# PUT /task/:task_id/link/:target/:target_id
	$task_with_id->put('/link/:target/:target_id', [target => $support_services ])
		->to(action => 'linkTaskWith')
		->name("LinkTaskWith");

	#imp
	# DELETE /task/:task_id/link/:target/:target_id
	$task_with_id->delete('/link/:target/:target_id', [target => $support_services ])
		->to(action => 'unlinkTaskWith')
		->name("UnlinkTaskWith");

	my $link = $r->route('/link/')->to(controller => 'Task');

	#imp
	# GET /task/link/:target/:target_id
	$link->get('/:target/:target_id', [target => $support_services] )
		->to(action => 'getTasksByLink')
		->name("GetTasksByLink");

	#imp
	# DELETE /task/link/:target/:target_id
	$link->delete('/:target/:target_id', [target => $support_services])
		->to(action => 'unlinkWithAllTasks')
		->name('UnlinkWithAllTasks');

	$link->put('/:target/:target_id/finish', [target => $support_services ])
		->to(action => 'linkFinish')
		->name('LinkFinish');
	
	$link->delete('/:target/:target_id/finish/', [target => $support_services ])
		->to(action => 'linkNotFinish')
		->name('LinkNotFinish');

		#Mojo::IOLoop->recurring(0.1,  sub {print ".", rand, "\n"});
}

1;
